// mine/pages/recipeslists/index.js
const $api = require("../../../api/mine").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t = this
  },
  onShow(){
    var t = this
    t.getTeacherDiet()
  },
  gotoadd(e){
    var t = this
    wx.navigateTo({
      url:'/mine/pages/recipesadd/index'
    })
  },
  gotorecipesinfo(e){
    var t = this
    wx.navigateTo({
      url:'/mine/pages/recipesinfo/index?week='+e.currentTarget.dataset.week
    })
  },
  // 老师我的食谱列表
  getTeacherDiet(){
    var t = this,
    data = {
      institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
      member_id:wx.getStorageSync('memberinfo').member_id
    }
    $api.getTeacherDiet(data).then(res=>{
      t.setData({
        lists:res.data
      })
    })
  },
  deleteTeacherDiet(e){
    var t= this,
    data = {
      institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
      member_id:wx.getStorageSync('memberinfo').member_id,
      child_diet_id:e.currentTarget.dataset.id
    }
    wx.showModal({

      title: '提示',
 
      content: '删除食谱',
 
      success: function (res) {
 
        if (res.confirm) {//这里是点击了确定以后
 
          $api.deleteTeacherDiet(data).then(res=>{
            console.log(res)
            wx.showToast({
              title: '删除成功',
            })
            t.onShow()
          })
 
        } else {//这里是点击了取消以后
 
          console.log('用户点击取消')
 
        }
 
      }
 
    })
    
  }
})